from flask import Flask
from apps.cms.views_cms import bp as cms_bp
from apps.common.views import bp as common_bp
from apps.api.views_index import bp as index_bp
from apps.api.views_trade import bp as trade_bp
from apps.api.views_user import bp as user_bp
from apps.api.views_task import bp as task_bp
from apps.api.views_version import bp as version_bp
from apps.mall import mall_bp as mall_bp
import config
from utils import JSONEncoder
from exit import db
from flask_cors import *


def create_app():
    app = Flask(__name__)
    app.config.from_object(config)
    app.register_blueprint(common_bp)
    app.register_blueprint(cms_bp)
    app.register_blueprint(index_bp)
    app.register_blueprint(trade_bp)
    app.register_blueprint(user_bp)
    app.register_blueprint(version_bp)
    app.register_blueprint(task_bp)
    app.register_blueprint(mall_bp)
    app.json_encoder = JSONEncoder
    CORS(app, supports_credentials=True)
    db.init_app(app)

    return app


app = create_app()


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000, debug=True, threaded=True)
